<template>
	<view class="add">
		<view class="add-head">
			<text>新增栏目</text>
			<view class="add-list">
				<text>栏目名称</text>
				<input type="text" v-model="title" placeholder="请输入栏目名称" />
			</view>
		</view>
		<view class="add-head">
			<text>新增栏目</text>
			<view class="add-list">
				<text>栏目数量</text>
				<input type="number" v-model="text" placeholder="请输入栏目数量" />
			</view>
		</view>
    <button class="btn" @click="addcar" hover-class="active-btn">确认新增</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: '',
        text: '',
        username: uni.getStorageSync('username') || ''
			};
		},
    methods:{
      addcar () {
        if (this.title === '') {
          uni.showToast({
            duration: 1500,
            icon: 'none',
            title: '请输入栏目名称'
          })
        } else if (this.text === '') {
          uni.showToast({
            duration: 1500,
            icon: 'none',
            title: '请输入栏目数量'
          })
        }
        this.$api({
          type: 'POST',
          url: '/index/index/addcar',
          data: {
            title: this.title,
            text: this.text,
            username: this.username
          }
        }).then((res) => {
          if (res.code === 200) {
            this.title = ''
            this.text = ''
            uni.showToast({
              duration: 1500,
              title: res.msg,
              icon: 'none'
            })
          } else if (res.code === 400) {
            uni.showToast({
              duration: 1500,
              title: res.msg,
              icon: 'none'
            })
          } else if (res.code === 401) {
            uni.showToast({
              duration: 1500,
              title: res.msg,
              icon: 'none'
            })
          }
        })
      }
    }
	}
</script>

<style lang="less">
.add{
	width: 100%;
	height: calc(100vh - 45px);
	background: #F0F0F0;
	.add-head{
		width: 100%;
		text{
			display: block;
			width: 100%;
			height: 100rpx;
			line-height: 100rpx;
			padding: 0 20rpx;
			box-sizing: border-box;
		}
		.add-list{
			display: flex;
			justify-content: space-between;
			align-items: center;
			background: #FFFFFF;
			input{
				text-align: right;
				padding-right: 20rpx;
			}
		}
	}
}
.btn {
  width: 600rpx;
  height: 100rpx;
  font-size: 30rpx;
  font-weight: 600;
  color: rgba(255, 255, 255, 1);
  line-height: 100rpx;
  margin-top: 60rpx;
  background: #2468cd;
  border-radius: 20rpx;
}
.active-btn {
  background-color: rgba(36, 104, 205, 0.8);
}
</style>
